package cn.sx.dao;

/*
 *@program:sx_emall_ssm
 *@author: sx
 *@desc:订单sql
 *@Time: 2020/10/12  11:34
 */

import cn.sx.entity.Orders;
import org.apache.ibatis.annotations.*;
import org.springframework.core.annotation.Order;

import java.util.List;

public interface OrderDao {
    @Select("select * from orders where user_id=#{userId} order by id desc limit #{begin},#{size}")
    List<Orders> selestListByUserid(@Param("userId")int userId,@Param("begin")int begin,@Param("size")int size);
    @Select("select * from orders where status=#{status} order by id desc limit #{begin},#{size}")
    List<Orders>selectListByStatus(@Param("status")byte status,@Param("begin")int begin,@Param("size")int size);

    @Select("select * from orders  where id=#{id}")
    Orders select(int id);

    @Insert("INSERT INTO orders (total,amount,`status`,paytype,`name`,phone,address,systime,user_id)" +
            " VALUE(#{total},#{amount},#{status},#{paytype},#{name},#{phone},#{address},NOW(),#{userId})")
    @SelectKey(keyProperty = "id",statement = "SELECT LAST_INSERT_ID()",before = false,resultType = Integer.class)
    boolean insert(Orders orders);
    @Update("update orders set status=#{status},paytype=#{paytype},name=#{name},phone=#{phone},address=#{address} where id =#{id}")
    boolean update(Orders orders);
    @Update("update orders set status=#{status} where id=#{id}")
    boolean updateStatus(@Param("id")int id,@Param("status")byte status);

    @Update("delete from orders where id=#{id}")
    int delete(int id);

    @Select("select count(*) from orders where user_id=#{userId}")
    int selectCountByUserid(@Param("userId") int userId);
    @Select("select count(*) from orders where status=#{status}")
    int selectCountByStatus(@Param("status")byte status);

    @Select("select * from orders order by id desc limit #{begin} ,#{size}")
    List<Orders> selectList(@Param("begin")int begin,@Param("size")int size);

    @Select("select count(*) from orders")
    int selectCount();
}
